<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
        <el-form-item label="推送人姓名" prop="invite_name">
          <el-input
            v-model="queryParams.invite_name"
            placeholder="推送人姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="推送人手机号" prop="invite_mobile">
          <el-input
            v-model="queryParams.invite_mobile"
            placeholder="推送人手机号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="经理人姓名" prop="manager_name">
          <el-input
            v-model="queryParams.manager_name"
            placeholder="经理人姓名"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="经理人手机号" prop="manager_mobile">
          <el-input
            v-model="queryParams.manager_mobile"
            placeholder="经理人手机号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:post:export']"
          >导出</el-button>
        </el-form-item>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1">
         
        </el-col>
       
      </el-row>
  
      <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column label="推送人姓名" align="center" prop="invite_name" />
        <el-table-column label="推送人手机号" align="center" prop="invite_mobile" />
        <el-table-column label="经理人姓名" align="center" prop="contacts" />
        <el-table-column label="经理人手机号" align="center" prop="tel_num" />
        <el-table-column label="邀请时间" align="center" prop="add_time" >
          <template slot-scope="scope">
            <div>{{parseTime(scope.row.add_time)}}</div>
          </template>
        </el-table-column>
        <el-table-column label="合同模版" align="center" prop="postSort" >
          <template slot-scope="scope">
            <el-button size="mini" type="primary" v-if="scope.row.manager_complete==1" @click="downloadManagerContract_" plain>下载</el-button>
          </template>
        </el-table-column>
        <el-table-column label="是否完善信息" align="center" prop="manager_complete" >
          <template slot-scope="scope">
             <div>{{ scope.row.manager_complete?'完善':'不完善' }}</div>
          </template>
        </el-table-column>
        <el-table-column label="所属服务中心" align="center" prop="service_name" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-document"
              @click="handleDetail(scope.row)"
              v-hasPermi="['system:post:document']"
            >查看</el-button>
            <!-- <el-button
              size="mini"
              type="text"
              icon="el-icon-refresh"
              @click="handleDelete(scope.row)"
              v-hasPermi="['system:post:refresh']"
            >更换门店</el-button> -->
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <el-dialog :title="title" :visible.sync="detailInfoPop" width="85%" name="" :show-close="false" append-to-body>
        <el-descriptions title="基础信息" :column="1" v-if="detailInfo">
            <el-descriptions-item label="经理人姓名">{{detailInfo.title}}</el-descriptions-item>
            <el-descriptions-item label="经理人手机">{{detailInfo.tel}}</el-descriptions-item>
            <el-descriptions-item label="推送人姓名">{{detailInfo.invite_name}}</el-descriptions-item>
            <el-descriptions-item label="推送人手机号">{{detailInfo.invite_mobile}}</el-descriptions-item>
            <el-descriptions-item label="提交时间">{{ parseTime(detailInfo.add_time)}}</el-descriptions-item>
            <el-descriptions-item label="合同模板">
              <el-button size="mini" type="primary" v-if="detailInfo.bank_cards&&detailInfo.bank_cards.personal_id&&detailInfo.bank_cards.bank_card_number" @click="downloadManagerContract_" plain>下载</el-button>
            </el-descriptions-item>
            <el-descriptions-item label="服务中心">{{detailInfo.service_name}}</el-descriptions-item>
            <el-descriptions-item label="所在地区">{{detailInfo.service_address_province}}</el-descriptions-item>
        </el-descriptions>  
        <template  v-if="detailInfo">
          <el-card class="box-card">
              <h2 style="font-weight: bold;">{{detailInfo.bank_cards&&detailInfo.bank_cards.personal_id&&detailInfo.bank_cards.bank_card_number?'已完善':'未完善'}}</h2>
              <el-descriptions title="身份证信息" :column="6">
                <el-descriptions-item label="身份证正面"  >
                  <el-image
                      v-if="detailInfo.bank_cards&&detailInfo.bank_cards.personal_id_face"
                      :preview-src-list="[detailInfo.bank_cards.personal_id_face,detailInfo.bank_cards.personal_id_back]"
                      style="width: 100px; height: 100px"
                      :src="detailInfo.bank_cards&&detailInfo.bank_cards.personal_id_face?detailInfo.bank_cards.personal_id_face:''"
                       ></el-image>
                  <el-image v-else style="width: 100px; height: 100px" src="" ></el-image>
                </el-descriptions-item>
                <el-descriptions-item label="身份证反面">
                  <el-image
                      v-if="detailInfo.bank_cards&&detailInfo.bank_cards.personal_id_back"
                      :preview-src-list="[detailInfo.bank_cards.personal_id_back,detailInfo.bank_cards.personal_id_back]"
                      style="width: 100px; height: 100px"
                      :src="detailInfo.bank_cards&&detailInfo.bank_cards.personal_id_back?detailInfo.bank_cards.personal_id_back:''"
                       ></el-image>
                  <el-image v-else style="width: 100px; height: 100px" src="" ></el-image>
                </el-descriptions-item>
                <el-descriptions-item label="姓名">{{detailInfo.bank_cards&&detailInfo.bank_cards.name?detailInfo.bank_cards.name:''}}</el-descriptions-item>
                <el-descriptions-item label="身份证号">{{detailInfo.bank_cards&&detailInfo.bank_cards.personal_id?detailInfo.bank_cards.personal_id:''}}</el-descriptions-item>
                <el-descriptions-item label="身份证有效期">{{detailInfo.bank_cards&&detailInfo.bank_cards.validPeriod?detailInfo.bank_cards.validPeriod:''}}</el-descriptions-item>
                <el-descriptions-item label="身份证签发单位">{{detailInfo.bank_cards&&detailInfo.bank_cards.issueAuthority?detailInfo.bank_cards.issueAuthority:''}}</el-descriptions-item>
              </el-descriptions>  
              <el-descriptions title="银行卡信息" :column="6">
                <el-descriptions-item label="银行卡账号">{{detailInfo.bank_cards&&detailInfo.bank_cards.bank_card_number?detailInfo.bank_cards.bank_card_number:''}}</el-descriptions-item>
                <el-descriptions-item label="开户行">{{detailInfo.bank_cards&&detailInfo.bank_cards.deposit_bank?detailInfo.bank_cards.deposit_bank:''}}</el-descriptions-item>
                <el-descriptions-item label="开户支行">{{detailInfo.bank_cards&&detailInfo.bank_cards.deposit_branch?detailInfo.bank_cards.deposit_branch:''}}</el-descriptions-item>
                <el-descriptions-item label="银行预留手机号">{{detailInfo.bank_cards&&detailInfo.bank_cards.phone?detailInfo.bank_cards.phone:''}}</el-descriptions-item>
              </el-descriptions>  
            </el-card>
        </template>
        <div style="text-align: center;">
          <el-button v-if="detailInfo" style="margin-top: 20px  ;" @click="detailInfoPop=false" type="primary">关闭</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { list,inviteeManager } from "@/api/system/customer";
  
  export default {
    name: "customer",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 是否显示弹出层
        detailInfoPop: false,
        detailInfo:null,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          manager_name: '',
          manager_mobile: '',
          invite_name: '',
          invite_mobile: ''
        },
        // 表单参数
        form: {}, 
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询岗位列表 */
      getList() {
        this.loading = true;
        list(this.queryParams).then(response => {
          this.postList = response.data.data;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      //get 详情
      getinviteeManager(id){
        inviteeManager({id:id}).then(res=>{
          this.detailInfo= res.data
          this.detailInfoPop = true;

        })
      },
      //下载合同
      downloadManagerContract_(){
        this.download('/admin/manager_invite/downloadManagerContract', {
          ...this.queryParams
        })
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          postId: undefined,
          postCode: undefined,
          postName: undefined,
          postSort: 0,
          status: "0",
          remark: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.postId)
        this.single = selection.length!=1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加岗位";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const postId = row.postId || this.ids
        getPost(postId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改岗位";
        });
      },
      handleDetail(row){
        this.getinviteeManager(row.id)
      },
      /** 提交按钮 */
      submitForm: function() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.postId != undefined) {
              updatePost(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addPost(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('/admin/manager_invite/exportExcel', {
          ...this.queryParams
        }, `post_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  